/*
 * Matt "Atmacen" Oliveri
 * This code is not part of JConfigGen. It's just an example of how to use it.
 */

import org.xml.sax.SAXParseException;
import javax.xml.parsers.SAXParserFactory;
import atma.jconfiggen.InvalidConfigException;
import atma.jconfiggen.sax.SAXHandler;

public class SAXTranslate
{
	private static void errorMsg(int line,String msg)
	{
		System.err.println("Line " + line + ": " + msg);
		System.exit(1);
	}

	public static void main(String[] args) throws Exception
	{
		SAXParserFactory pfact = SAXParserFactory.newInstance();
		pfact.setNamespaceAware(true); // SAXHandler assumes a namespace-aware parser.
		try
		{
			SAXHandler saxh = new SAXHandler();
			pfact.newSAXParser().parse(System.in,saxh);
			saxh.getConfig().print(System.out);
		}
		catch (SAXParseException e) {errorMsg(e.getLineNumber(),e.getMessage());}
		catch (InvalidConfigException e)
		{
			System.out.println(); // End the line in the incomplete output of print(), in case stdout and stderr are both the terminal.
			errorMsg(e.line,e.getMessage());
		}
	}
}
